package cn.itcast.com.homework.day725;
/*
2. 统计大串中小串出现的次数
举例：在字符串” woaijavawozhenaijavawozhendeaijavawozhendehenaijavaxinbuxinwoaijavagun”中java出现了5次

public int indexOf(String str, int fromIndex) {
        return indexOf(value, 0, value.length,
                str.value, 0, str.value.length, fromIndex);
    }
使用这个方法
 */
public class test2 {
    public static void main(String[] args) {
        String s = "woaijavawozhenaijavawozhendeaijavawozhendehenaijavaxinbuxinwoaijavagun";
        String j = "java";

        int java_length = j.length();
        int target = 0;
        int num = 0;
        while (true){
            if (s.indexOf(j,target) == -1){
                break;
            }
            else {
                //target往后移动4个
                target = s.indexOf(j,target) + java_length;
                num++;
            }
        }
        System.out.println("一共有"+num+"个"+j);

    }
}
